package com.haiyou.common.util.sys;


import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;


/**
 * 关于翻译语言使用的工具类
 */

public class LanUtil {

    /**
     * 获取请求头中需要加载的语言
     *
     * @param request
     * @return
     */
    public static String getAcceptLanguage(HttpServletRequest request) {
        String header = request.getHeader("Accept-Language");
        if (StringUtils.isEmpty(header)) {
            return "en";
        }
        String[] split = header.split(",");
        if (split.length > 0) {
            if (split[0].indexOf("=") < 0) {
                return split[0];
            }
            return "en";
        }
        return header;
    }
}
